const obj = {
  a: 1,
  b: 2,
  c: 3,
  d: {
    a: 1,
    b: 2,
  },
};

function isObject(val) {
  return typeof val === "object" && val !== null;
}
function reactive(obj) {
  const proxy = new Proxy(obj, {
    get(target, k) {
      if (isObject(target[k])) {
        return reactive(target[k]);
      }
      console.log("读取", target[k]);
    },
    set(target, k, val) {
      if (target[k] === val) {
        return;
      }
      target[k] = val;
      console.log("更新", target, k, val);
    },
  });
  return proxy;
}
const proxy = reactive(obj);

// proxy.a;
// proxy.a = 3;
// proxy.d.a;
proxy.d.a = 8;
// proxy.d.a = 4;
